<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<form action="" method="post">
			<table border="1" cellspacing="0" cellpadding="10px" id="check1">
				<tr>
					<th></th>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>家庭住址</th>
				</tr>
				<tr>
					<th><input type="checkbox" name="" id="" value="" /></th>
					<th>刻晴</th>
					<th class="sex">女</th>
					<th>18</th>
					<th>璃月</th>
				</tr>
				<tr>
					<th><input type="checkbox" name="" id="" value="" /></th>
					<th>刻晴</th>
					<th class="sex">男</th>
					<th>年龄</th>
					<th>璃月</th>
				</tr>
				<tr>
					<th><input type="checkbox" name="" id="" value="" /></th>
					<th>可莉</th>
					<th class="sex">女</th>
					<th>18</th>
					<th>蒙德</th>
				</tr>
				<tr>
					<th><input type="checkbox" name="" id="" value="" /></th>
					<th>团长</th>
					<th class="sex">男</th>
					<th>18</th>
					<th>蒙德</th>
				</tr>
			</table>
		</form>
		<input type="checkbox" name="" id="checkAllId" value="" onclick="check_id();"/>全选
		<input type="checkbox" name="" id="checkAllId1" value="" onclick="check_id1();"/>全选男
		<input type="checkbox" name="" id="checkAllId2" value="" onclick="check_id2();"/>全选女
		<button type="button">删除</button>
	</body>
	<script type="text/javascript">
		function check_id(){
			var obj = document.getElementById('check1');
			var inputCK = obj.getElementsByTagName('input');
			console.log(inputCK);
			var checkAllValue = document.getElementById('checkAllId').checked;
			console.log(checkAllValue)
			for(var i=0;i<inputCK.length;i++){
				inputCK[i].checked = checkAllValue;
			}
		}
		function check_id1(){
			var man = document.getElementsByClassName('sex');
			for (var i=0;i<man.length;i++) {
				if (man[i].innerText == '男') {
					var obj = document.getElementById('check1');
					var inputCK = obj.getElementsByTagName('input');
					// console.log(inputCK);
					var checkAllValue = document.getElementById('checkAllId1').checked;
					// console.log(checkAllValue)
					inputCK[i].checked = checkAllValue;
				}
			}
		}
		function check_id2(){
			var women = document.getElementsByClassName('sex');
			for (var i=0;i<women.length;i++) {
				if (women[i].innerText == '女') {
					var obj = document.getElementById('check1');
					var inputCK = obj.getElementsByTagName('input');
					// console.log(inputCK);
					var checkAllValue = document.getElementById('checkAllId2').checked;
					// console.log(checkAllValue)
					inputCK[i].checked = checkAllValue;
				}
			}
		}
	</script>
</html>
